﻿Imports System.Xml.Serialization
Imports System.Xml

Namespace CMISObjects
   <XmlRoot("content", Namespace:=CmisNamespaceConstants.Atom)>
   Public Class AtomContent
      Implements IXmlSerializable
      Public Sub New()

      End Sub

      Public Sub New(src As String, mediaType As String)
         _src = src
         _mediaType = mediaType
      End Sub
      Private _src As String
      Public ReadOnly Property SRC As String
         Get
            Return _src
         End Get
      End Property

      Private _mediaType As String
      Public ReadOnly Property MediaType As String
         Get
            Return _mediaType
         End Get
      End Property


      Public Function GetSchema() As System.Xml.Schema.XmlSchema Implements System.Xml.Serialization.IXmlSerializable.GetSchema
         Return Nothing
      End Function

      Public Sub ReadXml(reader As System.Xml.XmlReader) Implements System.Xml.Serialization.IXmlSerializable.ReadXml
         Dim doc As New System.Xml.XmlDocument()
         doc.Load(reader)
         Dim node As XmlNode = Common.GetItemCaseInsensitiveFromXML(doc, Common.GetXMLRootName(GetType(ContentContainer)))
         For Each child As XmlAttribute In node.Attributes
            Dim lname As String = Common.GetNodeNameWithoutPrefix(child).ToLowerInvariant
            If lname.Equals("type") Then
               _mediaType = child.InnerText
            ElseIf lname.Equals("src") Then
               _src = child.InnerText
            End If
         Next
      End Sub

      Public Sub WriteXml(writer As System.Xml.XmlWriter) Implements System.Xml.Serialization.IXmlSerializable.WriteXml
         writer.WriteAttributeString("type", CmisNamespaceConstants.Cmisra, Me.MediaType)
         writer.WriteAttributeString("src", CmisNamespaceConstants.Cmisra, Me.SRC)
      End Sub
   End Class
End Namespace